﻿package mortal.game.view.guild.cellrender
{
    import Message.Game.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.menu.*;
    import mortal.mvc.core.*;

    public class GuildMembersListCellRenderer extends GuildCellRenderer
    {
        private var _isSelected:Boolean = false;
        private var _bgSelected:ScaleBitmap;
        private var _bmpVip:GBitmap;
        private var _txtMemberName:GTextFiled;
        private var _txtPosition:GTextFiled;
        private var _txtLevel_Career:GTextFiled;
        private var _txtFightPower:GTextFiled;
        private var _txtTodayContribution:GTextFiled;
        private var _txtWeekContribution:GTextFiled;
        private var _txtTotalContribution:GTextFiled;
        private var _txtActives:GTextFiled;
        private var _txtState:GTextFiled;
        private var _txtFindingTalent:GButton;
        private var _isSelfMembers:Boolean;

        public function GuildMembersListCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.align = "center";
            this._txtMemberName = UIFactory.gTextField("", 30, 3, 100, 20, this);
            this._txtPosition = UIFactory.gTextField("xxxx", 134, 3, 60, 20, this, _loc_1);
            this._txtLevel_Career = UIFactory.gTextField("lv.90.", 210, 3, 75, 20, this);
            this._txtFightPower = UIFactory.gTextField("100000", 293, 3, 80, 20, this, _loc_1);
            this._txtTodayContribution = UIFactory.gTextField("100000", 368, 3, 55, 20, this, _loc_1);
            this._txtWeekContribution = UIFactory.gTextField("100000", 443, 3, 55, 20, this, _loc_1);
            this._txtTotalContribution = UIFactory.gTextField("100000", 517, 3, 55, 20, this, _loc_1);
            this._txtActives = UIFactory.gTextField("100000", 588, 3, 50, 20, this, _loc_1);
            this._txtState = UIFactory.gTextField("100000", 648, 3, 50, 20, this, _loc_1);
            this._txtFindingTalent = UIFactory.gButton("" + Language.getString(71102), 648, 3, 50, 20, this);
            UIFactory.bg(0, 25, 700, 1, this, ImagesConst.SplitLine);
            this._bgSelected = UIFactory.bg(0, 0, 700, 30, this, "selectFilter");
            this.update();
            return;
        }// end function

        public function update() : void
        {
            this.updateForSelfMembers();
            return;
        }// end function

        public function updateForSelfMembers() : void
        {
            this._isSelfMembers = true;
            this._txtState.visible = true;
            this._txtFindingTalent.visible = false;
            return;
        }// end function

        public function updateForFindTalentMembers() : void
        {
            this._isSelfMembers = false;
            this._txtState.visible = false;
            this._txtFindingTalent.visible = true;
            this._txtFindingTalent.configEventListener(MouseEvent.CLICK, this.onFindingTalent);
            return;
        }// end function

        private function onFindingTalent(event:MouseEvent) : void
        {
            var memberInfo:SGuildMember;
            var onCloseHandler:Function;
            var e:* = event;
            onCloseHandler = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_INVITE, {id:memberInfo.miniPlayer.entityId.id, type:EInviteMode._EInviteForDigMember}));
                }
                return;
            }// end function
            ;
            e.stopImmediatePropagation();
            if (Cache.instance.guild.selfGuildInfo.memberList.length >= Cache.instance.guild.selfGuildInfo.baseInfo.maxPlayerNum)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71103));
                return;
            }
            memberInfo = this._txtFindingTalent.Data as SGuildMember;
            if (!memberInfo.miniPlayer.online)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71104));
                return;
            }
            if (Cache.instance.guild.selfGuildInfo.baseInfo.resource < GameConst.TDigGuildMemberResoureCost)
            {
                MsgManager.showRollTipsMsg(Language.getString(70541));
                return;
            }
            Alert.show(Language.getStringByParam(70540, GameConst.TDigGuildMemberResoureCost), null, Alert.OK | Alert.CANCEL, null, onCloseHandler);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:* = param1 as SGuildMember;
            PlayerMenuRegister.UnRegister(this);
            if (_loc_2.miniPlayer.online)
            {
                PlayerMenuRegister.Register(this, _loc_2.miniPlayer, PlayerMenuConst.GuildMemberOnlineOpMenu);
                var _loc_3:* = GuildUtil.MemberOnlineColor;
                this._txtState.textColor = GuildUtil.MemberOnlineColor;
                var _loc_3:* = _loc_3;
                this._txtActives.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtTotalContribution.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtWeekContribution.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtTodayContribution.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtLevel_Career.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtFightPower.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtPosition.textColor = _loc_3;
                this._txtMemberName.textColor = _loc_3;
            }
            else
            {
                PlayerMenuRegister.Register(this, _loc_2.miniPlayer, PlayerMenuConst.GuildMemberOnlineOpMenu);
                var _loc_3:* = GuildUtil.MemberOfflineColor;
                this._txtState.textColor = GuildUtil.MemberOfflineColor;
                var _loc_3:* = _loc_3;
                this._txtActives.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtTotalContribution.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtWeekContribution.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtTodayContribution.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtLevel_Career.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtFightPower.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtPosition.textColor = _loc_3;
                this._txtMemberName.textColor = _loc_3;
            }
            this._txtMemberName.text = _loc_2.miniPlayer.name;
            this._txtPosition.text = GameDefConfig.instance.getItem("EGuildPostion", _loc_2.position).text;
            if (_loc_2.miniPlayer.online)
            {
                this._txtPosition.textColor = parseInt(GameDefConfig.instance.getItem("EGuildPostion", _loc_2.position).text1.split("#")[1], 16);
            }
            this._txtLevel_Career.text = "lv." + _loc_2.miniPlayer.level + "." + GameDefConfig.instance.getItem("ECareer", _loc_2.miniPlayer.career).text;
            this._txtFightPower.text = _loc_2.miniPlayer.combat.toString();
            this._txtTodayContribution.text = _loc_2.contributionDay.toString();
            this._txtWeekContribution.text = _loc_2.contributionWeek.toString();
            this._txtTotalContribution.text = _loc_2.totalContribution.toString();
            this._txtActives.text = _loc_2.activity.toString();
            if (_loc_2.miniPlayer.online)
            {
                this._txtActives.textColor = GlobalStyle.colorChenUint;
            }
            this._txtState.text = _loc_2.miniPlayer.online ? ("" + Language.getString(71105)) : (GuildUtil.getMemberOfflineState(_loc_2.lastLogoutDt));
            this._txtFindingTalent.Data = _loc_2;
            if (!this._isSelfMembers)
            {
                this._txtFindingTalent.visible = true;
            }
            if (_loc_2.position >= EGuildPosition._EGuildPresbyter)
            {
                this._txtFindingTalent.visible = false;
            }
            return;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            this._isSelected = param1;
            if (this._isSelected)
            {
                this._bgSelected.visible = true;
            }
            else
            {
                this._bgSelected.visible = false;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._isSelfMembers = false;
            return;
        }// end function

    }
}
